package com.ofek.applicationbase.forms;

import java.util.ArrayList;

import com.ofek.applicationbase.utils.Delegate;

public class Broadcaster<ListenerType> {
	protected final ArrayList<ListenerType> listeners = new ArrayList<ListenerType>();
	public boolean register(final ListenerType listener) {
		if (listeners.contains(listener)) return false;
		return listeners.add(listener);
	}
	public boolean unregister(final ListenerType listener) {
		return listeners.remove(listener);
	}
	/**
	 * you are being fed with all the listeners, invoke the method needs to be invoked in order to broadcast the event
	 * @param invokeIt
	 */
	public void broadcast(final Delegate<ListenerType> invokeIt) {
		for (final ListenerType l : listeners) 
			invokeIt.invoke(l);
	}
}
